//16pts
#include<bits/stdc++.h>
using namespace std;
int _47,n,m;
int a[1000005],c[1000005];
vector<int>d[47];
int na[1000005];
int tmp[1000005];
int ans[1000005];
int fun(int x){
	for(int i=0;i<=47/2;i=i+1){
		if((1<<i)>=x)return i;
	}
	return 32;
}
int main(){
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i=i+1){
		scanf("%d",&a[i]);
	}
	bool f=0;
	for(int i=1;i<=m;i=i+1){
		scanf("%d",&c[i]);
		if(c[i]!=(1<<(fun(c[i])))){
			f=1;
		}
	}
	if(f){
		return 0;
	}
	int K=fun(n);
	string s;
	for(int i=1;i<=K;i=i+1){
		cin>>s;
		for(int j=0;j<(1<<(K-i));j=j+1){
			d[i].push_back(s[j]-'0');
		}
	}
	cin>>_47;
	int x[4];
	for(int i=0;i<4;i=i+1)scanf("%d",&x[i]);
	for(int i=1;i<=n;i=i+1){
		a[i]=(a[i]^x[i%4]);
		na[i-1]=i;
	}
	ans[1]=1;
	for(int i=1;i<=K;i=i+1){
		for(int j=0;j<(1<<(K-i));j=j+1){
			int ll=j*2+d[i][j];
			if(a[na[ll]]>=i){
				tmp[j]=na[ll];
			}
			else tmp[j]=na[j*2+1-d[i][j]];
			if(j==0){
				ans[1<<i]=tmp[j];
			}
		}
		for(int j=0;j<(1<<(K-i));j=j+1){
			na[j]=tmp[j];
		}
	}
	int aa=0;
	for(int i=1;i<=m;i=i+1){
		aa=(aa^(i*ans[c[i]]));
	}
	cout<<aa<<endl;
	return 0;
}
